function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return unescape(r[2]); return null;
}

function getAddress() {
	//获取用户信息
	$.ajax({
		cache:true,
		type:"GET",
		url:"/dingcan/system/getAppUser.do",
		async:false, //为true无法使用jquery
		error: function(data) {
			localStorage.clear();
			window.location.href = "login.html";
		},
		success:function(data) {
			s(data);
		}
	});
}

function s(data) {
	
	var json = $api.strToJson(data);
	json = json.data;
	var address = json.address;
	var username = json.fullname;
	var phone = json.username;
	var ele = $(".address");
	var html = '<li id="style1"><input type="radio" value="' + address + '"  name="address" checked onclick="changeColor(1)"/><label for="address">'+ address + '（' + username+ '收）' +'<span class="fontcolor">'+ phone +'</span></label></li>';
	ele.empty();
	ele.html(html);
}

function upload() {
	$.ajax({
		cache:true,
		type:"POST",
		url:"/dingcan/dingcan/addOrder.do",
		data: $("#update_order").serialize(),
		async:false, //为true无法使用jquery
		error: function(data) {
			alert("提交失败");
		},
		success:function(data) {
			alert(data);
			
			changeCart();
		}
	});
}

function init() {
	getAddress();
	
	var yunfei = getQueryString("yunfei");
	var ids = getQueryString("ids");
	var prices = getQueryString("total");
	$(".yunfei").text(yunfei);
	$("#prices").text(prices);
	$("#total").text(parseFloat(yunfei) + parseFloat(prices));
	$("input[name='orderPrice']").attr("value",(parseFloat(yunfei) + parseFloat(prices)));
	$("input[name='ids']").attr("value",ids);
	$.ajax({
		cache:true,
		type:"GET",
		url:"/dingcan/dingcan/findFood.do?ids="+ids,
		async:true,
		error:function(data) {
			alert("error");
		},
		success:function(data) {
			var result = $.parseJSON(data).result;

			var html = "<table><th>名称</th><th>数量</th><th>价格</th>";
			for(var i = 0; i < result.length; i++) {
				var item = result[i];
				html += "<tr><td>"+item.foodName+"</td> <td>1</td> <td>￥"+item.foodPrice+"</td></tr>";
			    
			}
			html += "</table>";
			var table = $("#goodsList");
			table.html(html);
		}
	});
	
}

$(function() {
	init();
});